package com.example.doctorsystem.controller;

import com.example.doctorsystem.model.Patient;
import com.example.doctorsystem.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/patients")
@CrossOrigin(origins = "*")
public class PatientController {

    @Autowired
    private PatientService patientService;

    @PostMapping("/register")
    public String register(@RequestBody Patient patient) {
        int result = patientService.register(patient);
        return result > 0 ? "注册成功" : "注册失败";
    }

    @PostMapping("/login")
    public Patient login(@RequestParam String email, @RequestParam String password) {
        return patientService.login(email, password);
    }

    @GetMapping
    public List<Patient> allPatients() {
        return patientService.getAllPatients();
    }
}
